#region Using Statements
using System;
using System.Timers;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
#endregion

namespace SkyBurner
{
    public class DynamicCodeManager : BaseDrawableObject
    {
        protected Collection<BaseDrawableObject> m_drawableObjects = new Collection<BaseDrawableObject>();

        public DynamicCodeManager(BaseGame game)
            : base(game)
        {

        }

        public override void Update(GameTime gameTime, Camera pActiveCamera)
        {
            base.Update(gameTime, pActiveCamera);

            for (int i = 0; i < m_drawableObjects.Count; i++)
                m_drawableObjects[i].Update(gameTime, pActiveCamera);
        }

        public override void Draw(GameTime gameTime, Camera pActiveCamera)
        {
            base.Draw(gameTime, pActiveCamera);

            for (int i = 0; i < m_drawableObjects.Count; i++)
                m_drawableObjects[i].Draw(gameTime, pActiveCamera);
        }

        public void CreateVolumetricCloud(BaseWorld pBaseWorld, XMLPropertyBag pXMLConfig)
        {
            // create a volumetric cloud in front of player...
            Vector3 cloudPosition = pXMLConfig.GetValue<Vector3>("Position", XMLPropertyBagValueType.vtVector3);
            int particleCount = pXMLConfig.GetValue<int>("ParticleCount", XMLPropertyBagValueType.vtInteger);
            Vector3 maxBoundingBox = pXMLConfig.GetValue<Vector3>("BoundingVolume", XMLPropertyBagValueType.vtVector3);
            String particleTexture = pXMLConfig.GetValue<String>("ParticleTexture", XMLPropertyBagValueType.vtString);
            Random rnd = new Random();

            for (int i = 20; i >= 0; i--)
            {
                Vector3 vRndPosition = new Vector3(15.0f * (0.5f - (float)rnd.NextDouble()),
                                                   3.0f * (float)rnd.NextDouble(),
                                                   i * 3.5f);

                VolumetricCloud volumetricCloud = new VolumetricCloud(m_Game,
                                                                      pBaseWorld,
                                                                      0,
                                                                      cloudPosition + vRndPosition,
                                                                      particleCount,
                                                                      new BoundingBoxEx(Vector3.Zero, maxBoundingBox),
                                                                      m_Game.ContentManager.Load<Texture2D>(particleTexture));

                m_drawableObjects.Add(volumetricCloud);
            }
        }
    }
}